class Order < ActiveRecord::Base
  has_many :line_items
  
  PAYMENT_TYPES = [
    ["Chèques", "check"],
    ["Carte de Crédit", "cc"],
    ["Bon de portage", "po"],
    ["Compte Bancaire aux iles caïmans", "cbc"],
    ["Dons d'organe", "do"],
    ["Payage de rondelle", "pd"]
  ]
  
  validates_presence_of :name, :address, :phone, :pay_type
  validates_inclusion_of :pay_type, :in => PAYMENT_TYPES.map {|disp, value| value}
  
  def add_line_items_from_cart(cart)
    cart.items.each do |item|
      li = LineItem.from_cart_item(item)
      line_items << li
    end
  end
end
